<?php

class Login extends CI_Controller {

	function __construct()
	{
		parent::__construct();	
		//$this->is_logged_in(); 
	}
	function index()
	{
		//$data['main_content'] = 'login_form'; //load login_form.php under 'views'
		//$this->load->view('includes/template', $data); //parse that to templ
		$this->load->view('login_form');
	}
	function validate_credentials()
	{		
		$this->load->model('membership_model');
		$query = $this->membership_model->validate();
		
		if($query) // if the user's credentials validated...
		{
			$data = array(
				'username' => $this->input->post('username'),
				'is_logged_in' => true
			);
			$this->session->set_userdata($data);
			redirect('metrics/general_status');
		}
		else // incorrect username or password
		{
			$this->index();
		}
	}	
	
	function logout()
	{
		$this->session->sess_destroy();
		$this->index();
	}
	function is_logged_in()
	{
		$is_logged_in = $this->session->userdata('is_logged_in');
		if(!isset($is_logged_in) || $is_logged_in != true)
		{
			//echo 'You don\'t have permission to access this page. <a href="../login">Login</a>';	
			//die();		
			//$this->load->view('login_form');
		}
		else
		{
			redirect('getdata/get_all_metrics')	;
		}
	}
}
?>
